#include <linux/i2c-dev.h>
#include "std_c.h"
#include "i2c.h"
#include "raspi.h"
#include "stdio.h"

#define I2C_WRITE 0x00
#define I2C_READ 0x01

//--------------------------------------------------------------------------
//      PCF8574 Ausgaenge schreiben
//--------------------------------------------------------------------------

void pcf8574_output (int portexaddress, int portexdata)
{
        int data;
//        data = portexdata + 1;
	data = portexdata;

        I2C_Setup(I2C_SLAVE, portexaddress);
        if(I2cError)
           {
             I2C_PrintError();
             exit(1);
           }
        I2C_Write1(data);
//	printf("%u\t%u\t\r\n",portexaddress,portexdata);

}

//--------------------------------------------------------------------------
//       PCF8674 Eingaenge lesen
//--------------------------------------------------------------------------

int	 pcf8574_input	(int portexaddress, int *instat)
{
	uint8	error;
	uint8	d[3];
	error = 0;

        I2C_Setup(I2C_SLAVE, portexaddress);
        if(I2cError)
          {
            I2C_PrintError();
            exit(1);
          }
        DelayMs(30);
        I2C_Read(d,3);
	*instat = d[0];
//        printf("%02X\t:\t",d[0]);
//        printf("READ PDF8574 DONE\t\r\n");
}
